package com.car.carsharing.controller;

import com.car.carsharing.dto.ResponseDTO;
import com.car.carsharing.dto.TableListDto;
import com.car.carsharing.pojo.UserDeatil;
import com.car.carsharing.service.UserDeatilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserDeatilController {

    @Autowired
    private UserDeatilService userDeatilService;

    @RequestMapping("userDeatil")
    public ResponseDTO userDeatil(@RequestBody Map map){
        Integer result = userDeatilService.userDeatil(map);
        if(result == -1){
            return new ResponseDTO().error("存在空值");
        }
        if(result == 0){
            return new ResponseDTO().error("添加失败");
        }
        return new ResponseDTO().success("提交成功");
    }

    @RequestMapping("userList")
    public TableListDto getUserList(@RequestBody Map map){
        return userDeatilService.getUserList(map);
    }

    @RequestMapping("updateUser")
    public ResponseDTO updateUser(@RequestBody UserDeatil userDeatil){
        int r = userDeatilService.updateUser(userDeatil);
        return new ResponseDTO().success("修改成功");
    }

    @RequestMapping("deleteUser")
    public ResponseDTO deleteUser(@RequestBody UserDeatil userDeatil){
        int r = userDeatilService.deleteUser(userDeatil);
        return new ResponseDTO().success("删除成功");
    }


}
